package com.dks.controller;

import com.dks.models.FeedbackSheet;
import com.dks.repository.IFeedbackSheetRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("feedback-sheet")
@RestController
public class FeedbackSheetController{

    private IFeedbackSheetRepository feedbackSheetRepository;

    @Autowired
    public FeedbackSheetController(final IFeedbackSheetRepository feedbackSheetRepositoryIn){
        this.feedbackSheetRepository = feedbackSheetRepositoryIn;
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取课堂反馈列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: classId 班级id
     * @Param: teacherId 老师id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-feedback-sheet-list")
    public ResultModel<Object> getFeedbackSheetList(Integer pageNum, Integer pageSize,Integer classId,Integer teacherId) {
        if (null == teacherId ) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "teacherId");
        }

        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return feedbackSheetRepository.getFeedbackSheetList(pageNum,pageSize,classId,teacherId);
    }


    /**
     * @Author: Ah Nan
     * @Description: 获取课堂反馈详情
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: feedbackSheetiD 反馈id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-feedback-sheet-info")
    public ResultModel<Object> getFeedbackSheetInfo(Integer feedbackSheetId,Integer studentId) {

        if (null == feedbackSheetId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "feedbackSheetId");
        }
        return feedbackSheetRepository.getFeedbackSheetInfo(feedbackSheetId,studentId);
    }
    /**
     * @Author: Ah Nan
     * @Description: 获取模板(feedback_sheet_template表)详情
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: feedbackSheetiD 反馈id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-feedback-sheet-template-info")
    public ResultModel<Object> getFeedbackSheetTemplateInfo(Integer feedbackSheetTemplateId) {

        if (null == feedbackSheetTemplateId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "feedbackSheetTemplateId");
        }
        return feedbackSheetRepository.getFeedbackSheetTemplateInfo(feedbackSheetTemplateId);
    }

    /**
     * @Author: Ah Nan
     * @Description: 提交课堂反馈
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: feedbackSheetiD 反馈id
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("add-feedback-sheet")
    public ResultModel<Object> addFeedbackSheet(@RequestBody FeedbackSheet feedbackSheet) {

        if (null == feedbackSheet.getParentId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "ParentId");
        }
        if (null == feedbackSheet.getQsClassId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "ClassId");
        }
        if (null == feedbackSheet.getStudentId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "StudentId");
        }
        if (null == feedbackSheet.getTeacherId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "TeacherId");
        }
        if (null == feedbackSheet.getFeedbackSheetTemplateId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "feedbackSheetTemplateId");
        }
        if (null == feedbackSheet.getTopOneStatus()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "TopOneStatus");
        }
        if (null == feedbackSheet.getTopTwoStatus()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "TopTwoStatus");
        }
        if (null == feedbackSheet.getTopThreeStatus()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "TopThreeStatus");
        }
        if (null == feedbackSheet.getTopFourStatus()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "getTopFourStatus");
        }
        if (null == feedbackSheet.getTopFiveStatus()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "TopFiveStatus");
        }
        return feedbackSheetRepository.addFeedbackSheet(feedbackSheet);
    }
}
